package com.banciyuan.bcywebview.biz.circles.discover.tagnav;

import android.content.Context;
import android.graphics.Rect;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.banciyuan.bcywebview.utils.common.UIUtils;

/**
 * Created by squall on 2017/3/20.
 */

public class CircleItemDecoration extends RecyclerView.ItemDecoration {

    private Context mContext;

    public CircleItemDecoration(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        if (parent.getChildAdapterPosition(view) > 0) {
            GridLayoutManager.LayoutParams lp = (GridLayoutManager.LayoutParams) view.getLayoutParams();
            int spanIndex = lp.getSpanIndex();
            if ((spanIndex + 1) % 2 == 0) {
                outRect.left = UIUtils.dip2px(6, mContext);
            } else {
                outRect.right = UIUtils.dip2px(6, mContext);
            }
            if (parent.getAdapter() != null &&
            parent.getAdapter().getItemViewType(parent.getChildAdapterPosition(view)) == 1){
                outRect.top = UIUtils.dip2px(11, mContext);
            }
        }

    }
}
